*Figure E6, Rural Pincodes
clear all 
use figure_e6

keep if pin_rural == 1

gen avg = .
gen inter = . 

forvalues i = 0(1)24 { 
local c = `i' + 1
quietly sum delta_pos_totalamount if dist_cc >= `i' & dist_cc < `c'
replace avg = r(mean) if dist_cc >= `i' & dist_cc < `c'
replace inter = (`i' + `c')/2 if dist_cc >= `i' & dist_cc < `c'
} 

duplicates drop inter, force
drop if avg == .

scatter avg inter || lfit avg inter, msize(vsmall) graphregion(color(white)) ///
ytitle("Difference (Log)", height(5)) legend(off) xtitle("Distance to Currency Chest (km)", height(5)) subtitle("Digital Transactions" "Rural Pincodes") ylabel(#3)

*Figure E6, Urban Pincodes
clear all 
use figure_e6

keep if pin_rural == 0

gen avg = .
gen inter = . 

forvalues i = 0(1)24 { 
local c = `i' + 1
quietly sum delta_pos_totalamount if dist_cc >= `i' & dist_cc < `c'
replace avg = r(mean) if dist_cc >= `i' & dist_cc < `c'
replace inter = (`i' + `c')/2 if dist_cc >= `i' & dist_cc < `c'
} 

duplicates drop inter, force
drop if avg == .

scatter avg inter || lfit avg inter, msize(vsmall) graphregion(color(white)) ///
ytitle("Difference (Log)", height(5)) legend(off) xtitle("Distance to Currency Chest (km)", height(5)) subtitle("Digital Transactions" "Urban Pincodes") ylabel(#3)

*Figure E6, High Pre-Treatment PoS Terminal Density
clear all 
use figure_e6

keep if high_pos == 1

gen avg = .
gen inter = . 

forvalues i = 0(1)24 { 
local c = `i' + 1
quietly sum delta_pos_totalamount if dist_cc >= `i' & dist_cc < `c'
replace avg = r(mean) if dist_cc >= `i' & dist_cc < `c'
replace inter = (`i' + `c')/2 if dist_cc >= `i' & dist_cc < `c'
} 

duplicates drop inter, force
drop if avg == .

scatter avg inter || lfit avg inter, msize(vsmall) graphregion(color(white)) ///
ytitle("Difference (Log)", height(5)) legend(off) xtitle("Distance to Currency Chest (km)", height(5)) subtitle("Digital Transactions" "High POS") ylabel(#3)

*Figure E6, Low Pre-Treatment PoS Terminal Density
clear all 
use figure_e6

keep if high_pos == 0

gen avg = .
gen inter = . 

forvalues i = 0(1)24 { 
local c = `i' + 1
quietly sum delta_pos_totalamount if dist_cc >= `i' & dist_cc < `c'
replace avg = r(mean) if dist_cc >= `i' & dist_cc < `c'
replace inter = (`i' + `c')/2 if dist_cc >= `i' & dist_cc < `c'
} 

duplicates drop inter, force
drop if avg == .

scatter avg inter || lfit avg inter, msize(vsmall) graphregion(color(white)) ///
ytitle("Difference (Log)", height(5)) legend(off) xtitle("Distance to Currency Chest (km)", height(5)) subtitle("Digital Transactions" "Low POS") ylabel(#3)
